﻿using System.ServiceModel;
using AutoMapper;
using Sautom.Queries;
using Sautom.WcfServer.Interfaces;
using Sautom.WcfServer.TransportDto;

namespace Sautom.WcfServer.Services
{
    //todo T4
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    sealed public partial class AuthorizationService : IAuthorizationService 
    {
        private readonly Sautom.Services.AuthorizationService _authorizationService;

        #region Properties
        public IAuthorizationFinder AuthorizationFinder { get; set; }
        #endregion

        #region Constructors
        public AuthorizationService(IAuthorizationFinder authorizationFinder, Sautom.Services.AuthorizationService authorizationService)
        {
            _authorizationService = authorizationService;
            AuthorizationFinder = authorizationFinder;
        }

        #endregion
        
        #region Implementation of IAuthorizationService

        public AunthorizationCredentialsDtoOutput GetCredentials(string name, string password)
        {
            return Mapper.Map<AunthorizationCredentialsDtoOutput>(AuthorizationFinder.GetCredentials(name, password));
        }

        public bool ChangePassword(string name, string password, string newPassword)
        {
            return _authorizationService.ChangePassword(name, password, newPassword).IsValid;
        }

        #endregion
    }
}
